/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ages.test

import com.ages.graphics.GLDraw
import com.ages.graphics.ViewportSwitcher
import com.ages.input.Keyboard
import com.ages.math.Vector3D
import com.sun.opengl.util.GLUT
import java.awt.event.KeyListener
import javax.media.opengl.GL
import com.ages.entity.Actor

class Teapot(p:Vector3D,keys:Keyboard) extends Actor{
  pos = p
  var rotation = 0.0
  val SPEED = 0.03
  def think(){
    if(keys.space && vel.Y==0)
      vel = Vector3D(vel.X,0.5,0)

    if(keys.left)
      vel = vel plus Vector3D(-SPEED,0,0)

    if(keys.right)
      vel = vel plus Vector3D(SPEED,0,0)

    if(pos.Y<0)
      {
        vel = Vector3D(0,0,0)
        pos = Vector3D(pos.X,0,0)
      }
      if(pos.Y>0)
        vel = vel minus Vector3D(0,0.03,0)
      vel = vel dot 0.97
      pos = pos plus vel
      
  }
  def draw(gl:GL){
    
    def tpot = () =>{
    val mat_ambient = Array[Float](0.7f,0.7f,0.7f,1)
    val mat_diffuse = Array[Float](0.1f,0.8f,0.1f,1)
    val mat_specular = Array[Float](1,1,1,1)
    val high_shininess = Array[Float](100.0f)
    val no_mat = Array[Float](0,0,0,1)
   gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT, mat_ambient,0);
   gl.glMaterialfv(GL.GL_FRONT, GL.GL_DIFFUSE, mat_diffuse,0);
   gl.glMaterialfv(GL.GL_FRONT, GL.GL_SPECULAR, mat_specular,0);
   gl.glMaterialfv(GL.GL_FRONT, GL.GL_SHININESS, high_shininess,0);
   gl.glMaterialfv(GL.GL_FRONT, GL.GL_EMISSION, no_mat,0);


      gl.glColor4d(0,1,0,1)
      gl.glMatrixMode(GL.GL_MODELVIEW)
      val glut = new GLUT()
      rotation+=0.5
      gl.glRotated(rotation,0,1,0)
      glut.glutSolidTeapot(1)
    }
    val spot:Vector3D = Vector3D(pos.X,pos.Y,pos.Z-7)
    ViewportSwitcher.setup3DView(gl)

    GLDraw draw tpot at spot on gl
  }


}
